﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Characters
{
    public class Avatar
    {
        #region properties

        #region attributes
        public int AvatarWalkStep;
        public int Health;
        //public int Energy;
        public bool CanMove; //determine if vatar can move or not
        public bool IsAlive;
        //public List<Util.Classes.Item> CollectedItems { get; set; } //list of collected items
        #endregion

        #region movement
        //placement enum
        public enum CheckpointPosition { None,LeftUp, LeftDown, RightUp, RightDown };

        public bool DrawingMovePatternStarted; //set to true when user started drawing move pattern
        public bool DrawingMovePatternEnd;//set to true when user finished drawing move pattern
        public bool DrawingMovePatternCanceled;
        public bool IsFollowing;
        public List<Helpers.MovePatternCheckpoint> MovePoints; //checkpoints for avatar to get before reaching destination
        #endregion

        #endregion

        #region public fields
        public const int FramesPerSec = 2;

        public float AnimatingInterval = 200f;
        public float AnimationTimer = 0f;

        public bool DrawAvatarHurt;
        public int CheckpointsReached; //number of checkpoints reached,used to take away battery
        #region move patern
        public float DistanceToTarget;
        public bool IsMoving;
        public Vector2 MovementVector = new Vector2();

        #endregion

        #endregion

        #region private fields
        private int _AnimationCt = 0;
        private List<int[]> _NPCFOVRects;//list of fov circles, where 1 of them spotted avatar

        #region TIME INVERVAL HELPERS
        private double _SetTime;
        #endregion

        #region move pattern
        private int _MoveCheckpointIndex = 0;
        private int _IndexValueHolder = 0;
        private bool _AddCheckpoint = true; //add checkpoint
        public Helpers.MovePatternCheckpoint CurrentMoveCheckpoint;
        public Helpers.MovePatternCheckpoint TargetMoveCheckpoint;

        private bool _XReached;//set to true if avatar gets to the checkpoint
        private bool _YReached; //set to true if avatar gets to the checkpoint
        private int _CurrentMoveCheckpointIndex; //index of the move checkpoint in the list
        private bool _MoveDirectionDetermined;
        //private int _MoveDirectionReassignHelpValue;

        #endregion

        #region using items

        #region throwing
        private bool _DrawThrowDirectionArrows;
        private Rectangle _ThrowDirectionArrowUp;
        private Rectangle _ThrowDirectionArrowDown;
        private Rectangle _ThrowDirectionArrowRight;
        private Rectangle _ThrowDirectionArrowLeft;
        public bool ThrowDirectionArrowsDrawn;
        #endregion


        #endregion

        #endregion




        #region character states
        //All states thath main character can be in
        public enum States { IdleRight, IdleLeft, IdleUp, IdleDown, GoRight1, GoRight2, GoLeft1, GoLeft2, GoDown1, GoDown2, GoUp1, GoUp2, GoCrossUpRight1, GoCrossUpRight2, GoCrossDownRight1, GoCrossDownRight2, GoCrossLeftUp1, GoCrossLeftUp2, GoCrossLeftDown1, GoCrossLeftDown2, Hurt1, Hurt2, Death1, Death2, LayDownRight, LayDownLeft, LayDownUp, LayDown, LayDownCrossUpRight, LayDownCrossUpLeft, LayDownCrossDownRight, LayDownCrossDownLeft, DiveUp, DiveDown, DiveRight, DiveLeft, DiveCrossUpRight, DiveCrossUpLeft, DiveCrossDownRight, DiveCrossDownLeft, ThrowDown,ThrowUp,ThrowRight,ThrowLeft };
        public States CurrentState;
        public States PreviousState;
        public Util.Helpers.PublicEnums.AvatarPosition Position;
        public Util.Helpers.PublicEnums.AvatarPosition PreviousPosition;
        #endregion

        #region other
        public Vector2 CurrentPosition;
        public int Width;
        public int Height;
        public int Offset;
        public bool IsBeingHurt;
        public bool IsSpottedByNPCButHidden;
        public string NpcThatSpottedID;


        //helper
        public Vector2 FuturePosition; //position that will be next

        #endregion




        #region methods

        #region private

        /// <summary>
        /// if avatar is spotted by NPC but hidden
        /// an umbrella is drawn over avatar's head
        /// meaning it's protected
        /// </summary>
        private void _DrawUmbrella()
        {
            //declare
            int[] avatarRect;
            bool avatarStillInSight = false;

            try
            {
                if (IsSpottedByNPCButHidden)
                {

                    //create avatar rectangle
                    avatarRect = new int[]{(int)CurrentPosition.X + Offset, (int)CurrentPosition.Y, Width - (Offset * 2), Height - (Offset * 2)};

                    //first see if umbrella is still needed, if avatar is still in a fov of npc
                    for (int i = 0; i < _NPCFOVRects.Count; i++)
                    {
                        
                        if(World.WorldManager.IsObstacleTouched(_NPCFOVRects[i],avatarRect))
                        {
                            avatarStillInSight = true;
                            break;
                        }
                    }

                    //draw umbrella only if avatar is still in sight
                    if (avatarStillInSight)
                    {
                        //draw an umbrella
                        Util.Cache.Draw(Util.Cache.GetTexture("HUDprotectionUmbrella").Text2D, new Rectangle((int)this.CurrentPosition.X - (this.Width / 2), (int)this.CurrentPosition.Y - (this.Height / 2), this.Width + (this.Width / 2), this.Height / 2), Color.White);

                    }
                    else
                    {
                        IsSpottedByNPCButHidden = false;
                        //also, set world.AwardingPoints=false
                        World.WorldManager.AddingPoints = false; //it's a safety switch, if avatar is spotted, it ensures that points are awarded only once
                    }

                }
                else
                {
                    _NPCFOVRects = null;
                }

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }


        #endregion




        /// <summary>
        /// default constructor
        /// </summary>
        public Avatar()
        {
            try
            {
                CurrentState = States.IdleDown;

                //set attributes
                Health = World.WorldManager.WorldConfig.AvatarHealth;
         
                AvatarWalkStep = World.WorldManager.WorldConfig.AvatarWalkSpeed;

                CanMove = true;
                IsAlive = true;
                DrawAvatarHurt = false;

                //CollectedItems = new List<Util.Classes.Item>();
                

                CurrentPosition = Vector2.Zero;
                FuturePosition = Vector2.Zero;
                Position = Util.Helpers.PublicEnums.AvatarPosition.Stand;
                //size
                Width = World.WorldManager.WorldConfig.AvatarWidth;
                Height = World.WorldManager.WorldConfig.AvatarHeight;

                //margin
                Offset = 0;

                IsSpottedByNPCButHidden = false;

                //avatar's animation interval
                AnimatingInterval = 40;
                IsBeingHurt = false;

                World.WorldManager.WorldConfig.EnergyBarWidth = Width * 3;
                

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }

        }

        /// <summary>
        /// Add collected item to the inventory
        /// </summary>
        /// <param name="item"></param>
        /// <param name="count"></param>
        public void AddItemToTheInventory(Util.Classes.Item item, int count)
        {
            try
            {
                //for (int i = 0; i < count; i++)
                //{
                //    //add as many items as count value
                //    this.CollectedItems.Add(item);

                //}

                //add to the inventory
                World.WorldManager.Inventory.Add(new Util.Classes.InventoryItem(item.Name,count,item));



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// add lives
        /// </summary>
        /// <param name="lives"></param>
        public void AddLives(int lives)
        {
            try
            {

                if (this.Health + lives > 100)
                {
                    this.Health = 100;
                }
                else
                {
                    this.Health += lives;
                }


                

                World.StorageManager.SaveWorldInfo();



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// When avatar is spotted
        /// but hidden
        /// umbrella is drawn over its head
        /// rectangles (circles) are needed for an updating purposes
        /// to know when to stop drawing umbrella (when avatar is no longer in a fov of npc)
        /// </summary>
        /// <param name="fovCircle1"></param>
        /// <param name="fovCircle2"></param>
        /// <param name="fovCircle3"></param>
        public void SetAvatarSpottedButHidden(int[] fovCircle1, int[] fovCircle2, int[] fovCircle3)
        {
            try
            {

                if (_NPCFOVRects == null)
                {
                    _NPCFOVRects = new List<int[]>();
                }

                _NPCFOVRects.Add(fovCircle1);
                _NPCFOVRects.Add(fovCircle2);
                _NPCFOVRects.Add(fovCircle3);

                IsSpottedByNPCButHidden = true;


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// increment timer
        /// </summary>
        /// <param name="ct"></param>
        public void ControlWalkAnimation()
        {
            try
            {
                _AnimationCt += 1;

                //reset animation timer every 4 game time loops
                //to slow down the animation
                if (_AnimationCt > 10)
                {
                    AnimationTimer = 0F;
                    _AnimationCt = 0;
                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// set state of the avatar
        /// </summary>
        /// <param name="state"></param>
        public void SetState(States state)
        {
            try
            {

                CurrentState = state;



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// set state of the avatar
        /// basing on Position
        /// </summary>
        /// <param name="state"></param>
        public void SetState(Util.Helpers.PublicEnums.AvatarPosition pos)
        {
            try
            {
                //basing on position
                //determin state of avatar, but it needs to be continous
                //so, if avatar is idle left, changes to lay down
                //then avatar should lay down left

                //if avatar does not immediately changtes state, then some state (determine state part) is missing, eg. goRight1, goRight2 etc.

                switch (pos)
                {
                    case Util.Helpers.PublicEnums.AvatarPosition.Stand:
                        {
                            this.Position = Util.Helpers.PublicEnums.AvatarPosition.Stand;

                            #region stand-determine state

                            //switch current state
                            switch (CurrentState)
                            {
                                case States.LayDown:
                                    {
                                        CurrentState = States.IdleDown;
                                        break;


                                    }
                                case States.LayDownUp:
                                    {
                                        CurrentState = States.IdleUp;
                                        break;
                                    }
                                case States.LayDownRight:
                                    {
                                        CurrentState = States.IdleRight;
                                        break;

                                    }
                                case States.LayDownLeft:
                                    {
                                        CurrentState = States.IdleLeft;
                                        break;


                                    }


                            }

                            #endregion


                            break;
                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Lay:
                        {
                            this.Position = Util.Helpers.PublicEnums.AvatarPosition.Lay;

                            #region lay down -determine state

                            //switch current state
                            switch (CurrentState)
                            {
                                case States.IdleDown:
                                    {
                                        CurrentState = States.LayDown;
                                        break;
                                    }
                                case States.IdleUp:
                                    {
                                        CurrentState = States.LayDownUp;
                                        break;
                                    }
                                case States.IdleLeft:
                                    {
                                        CurrentState = States.LayDownLeft;
                                        break;
                                    }
                                case States.IdleRight:
                                    {
                                        CurrentState = States.LayDownRight;
                                        break;
                                    }
                            }


                            #endregion

                            break;
                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Dive:
                        {
                            this.Position = Util.Helpers.PublicEnums.AvatarPosition.Dive;

                            #region dive -determine state

                            //switch current state
                            switch (CurrentState)
                            {
                                case States.IdleDown:
                                    {
                                        CurrentState = States.DiveDown;
                                        break;
                                    }
                                case States.IdleUp:
                                    {
                                        CurrentState = States.DiveUp;
                                        break;
                                    }
                                case States.IdleLeft:
                                    {
                                        CurrentState = States.DiveLeft;
                                        break;
                                    }
                                case States.IdleRight:
                                    {
                                        CurrentState = States.DiveRight;
                                        break;
                                    }
                                case States.LayDown:
                                    {
                                        CurrentState = States.DiveDown;
                                        break;


                                    }
                                case States.LayDownUp:
                                    {
                                        CurrentState = States.DiveUp;
                                        break;
                                    }
                                case States.LayDownRight:
                                    {
                                        CurrentState = States.DiveRight;
                                        break;

                                    }
                                case States.LayDownLeft:
                                    {
                                        CurrentState = States.DiveLeft;
                                        break;


                                    }
                            }


                            #endregion

                            break;
                        }





                }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// set state of the avatar
        /// basing on Position
        /// </summary>
        /// <param name="state"></param>
        public void SetIdle(Util.Helpers.PublicEnums.AvatarPosition pos)
        {
            try
            {
                //basing on position
                //determin state of avatar, but it needs to be continous
                //so, if avatar is idle left, changes to lay down
                //then avatar should lay down left

                //if avatar does not immediately changtes state, then some state (determine state part) is missing, eg. goRight1, goRight2 etc.

                switch (pos)
                {
                    case Util.Helpers.PublicEnums.AvatarPosition.Stand:
                        {


                            #region stand-determine state

                            //switch current state
                            switch (CurrentState)
                            {
                                case States.GoDown1:
                                    {
                                        CurrentState = States.IdleDown;
                                        break;


                                    }
                                case States.GoUp1:
                                    {
                                        CurrentState = States.IdleUp;
                                        break;
                                    }
                                case States.GoRight1:
                                    {
                                        CurrentState = States.IdleRight;
                                        break;

                                    }
                                case States.GoLeft1:
                                    {
                                        CurrentState = States.IdleLeft;
                                        break;


                                    }


                            }

                            #endregion


                            break;
                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Lay:
                        {
                            this.Position = Util.Helpers.PublicEnums.AvatarPosition.Lay;

                            #region lay down -determine state

                            //switch current state
                            switch (CurrentState)
                            {
                                case States.IdleDown:
                                    {
                                        CurrentState = States.LayDown;
                                        break;
                                    }
                                case States.IdleUp:
                                    {
                                        CurrentState = States.LayDownUp;
                                        break;
                                    }
                                case States.IdleLeft:
                                    {
                                        CurrentState = States.LayDownLeft;
                                        break;
                                    }
                                case States.IdleRight:
                                    {
                                        CurrentState = States.LayDownRight;
                                        break;
                                    }
                            }


                            #endregion

                            break;
                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Dive:
                        {
                            this.Position = Util.Helpers.PublicEnums.AvatarPosition.Dive;

                            #region dive -determine state

                            //switch current state
                            switch (CurrentState)
                            {
                                case States.IdleDown:
                                    {
                                        CurrentState = States.DiveDown;
                                        break;
                                    }
                                case States.IdleUp:
                                    {
                                        CurrentState = States.DiveUp;
                                        break;
                                    }
                                case States.IdleLeft:
                                    {
                                        CurrentState = States.DiveLeft;
                                        break;
                                    }
                                case States.IdleRight:
                                    {
                                        CurrentState = States.DiveRight;
                                        break;
                                    }
                                case States.LayDown:
                                    {
                                        CurrentState = States.DiveDown;
                                        break;


                                    }
                                case States.LayDownUp:
                                    {
                                        CurrentState = States.DiveUp;
                                        break;
                                    }
                                case States.LayDownRight:
                                    {
                                        CurrentState = States.DiveRight;
                                        break;

                                    }
                                case States.LayDownLeft:
                                    {
                                        CurrentState = States.DiveLeft;
                                        break;


                                    }
                            }


                            #endregion

                            break;
                        }

                }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// set state of the avatar
        /// restore previous state
        /// </summary>
        /// <param name="state"></param>
        public void SetPreviousState()
        {
            try
            {

                PreviousState = CurrentState;
                PreviousPosition = Position;


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        #region throw arrows

        /// <summary>
        /// show throw direction arrows
        /// </summary>
        public void ShowThrowArrows()
        {
            try
            {
                //create control rectangles,
                //that will be used to detect if an arrow is out of screen or not
                Rectangle UpBoundry = new Rectangle(0, -Util.Cache.GraphicsDevice.Viewport.Height, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height);
                Rectangle DownBoundry = new Rectangle(0, Util.Cache.GraphicsDevice.Viewport.Height, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height);
                Rectangle RightBoundry = new Rectangle(Util.Cache.GraphicsDevice.Viewport.Width, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height);
                Rectangle LeftBoundry = new Rectangle(-Util.Cache.GraphicsDevice.Viewport.Width, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height);

                #region arrow up

                _ThrowDirectionArrowUp = new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y - (this.Height + 10)-15, this.Width, this.Height + 10);

                if(UpBoundry.Intersects(_ThrowDirectionArrowUp))
                {
                    _ThrowDirectionArrowUp = new Rectangle(-1,-1,-1,-1);
                }

                #endregion

                #region arrow down

                _ThrowDirectionArrowDown = new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y + this.Height + 15, this.Width, this.Height + 10);

                if (DownBoundry.Intersects(_ThrowDirectionArrowDown))
                {
                    _ThrowDirectionArrowDown = new Rectangle(-1, -1, -1, -1);
                }

                #endregion

                #region arrow left

                _ThrowDirectionArrowLeft = new Rectangle((int)this.CurrentPosition.X - (this.Height + 15) - 15, (int)this.CurrentPosition.Y, this.Height + 15, this.Width + 10);

                if (LeftBoundry.Intersects(_ThrowDirectionArrowLeft))
                {
                    _ThrowDirectionArrowLeft = new Rectangle(-1, -1, -1, -1);
                }

                #endregion

                #region arrow right

                _ThrowDirectionArrowRight = new Rectangle((int)this.CurrentPosition.X + this.Width + 15, (int)this.CurrentPosition.Y, this.Height + 15, this.Width + 10);

                if (RightBoundry.Intersects(_ThrowDirectionArrowRight))
                {
                    _ThrowDirectionArrowRight = new Rectangle(-1, -1, -1, -1);
                }

                #endregion


                #region dispose of control rects
                UpBoundry = new Rectangle(-1, -1, -1, -1);
                DownBoundry = new Rectangle(-1, -1, -1, -1);
                RightBoundry = new Rectangle(-1, -1, -1, -1);
                LeftBoundry = new Rectangle(-1, -1, -1, -1);
                #endregion


                _DrawThrowDirectionArrows = true;



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Press throw direction arrow
        /// 
        /// </summary>
        /// <param name="tapPos"></param>
        public void PressThrowDirectionArrow(Vector2 tapPos)
        {
            try
            {
                //if thrown direction has been already chosen, if no throw direction arrows drawn, then  return
                if (World.WorldManager.ThrowDirectionChosen && !ThrowDirectionArrowsDrawn && World.WorldManager.ThrownItem.ThrowDirection!=Util.Helpers.PublicEnums.ItemMoveDirection.None)
                {
                    return;
                }


                //which throw arrow has been clicked?
                if ((tapPos.X >= _ThrowDirectionArrowUp.X && tapPos.X <= _ThrowDirectionArrowUp.X + _ThrowDirectionArrowUp.Width) && (tapPos.Y >= _ThrowDirectionArrowUp.Y && tapPos.Y <= _ThrowDirectionArrowUp.Y + _ThrowDirectionArrowUp.Height))
                {
                    //up arrow clicked
                    World.WorldManager.ThrownItem.ThrowDirection = Util.Helpers.PublicEnums.ItemMoveDirection.Up;
                    World.WorldManager.ThrowDirectionChosen = true;
                    World.WorldManager.ThrownItem.ThrowItem();
                    return;
                }

                if ((tapPos.X >= _ThrowDirectionArrowDown.X && tapPos.X <= _ThrowDirectionArrowDown.X + _ThrowDirectionArrowDown.Width) && (tapPos.Y >= _ThrowDirectionArrowDown.Y && tapPos.Y <= _ThrowDirectionArrowDown.Y + _ThrowDirectionArrowDown.Height))
                {
                    //udown arrow clicked
                    World.WorldManager.ThrownItem.ThrowDirection = Util.Helpers.PublicEnums.ItemMoveDirection.Down;
                    World.WorldManager.ThrowDirectionChosen = true;
                    World.WorldManager.ThrownItem.ThrowItem();
                    return;
                }

                if ((tapPos.X >= _ThrowDirectionArrowLeft.X && tapPos.X <= _ThrowDirectionArrowLeft.X + _ThrowDirectionArrowLeft.Width) && (tapPos.Y >= _ThrowDirectionArrowLeft.Y && tapPos.Y <= _ThrowDirectionArrowLeft.Y + _ThrowDirectionArrowLeft.Height))
                {
                    //left arrow clicked
                    World.WorldManager.ThrownItem.ThrowDirection = Util.Helpers.PublicEnums.ItemMoveDirection.Left;
                    World.WorldManager.ThrowDirectionChosen = true;
                    World.WorldManager.ThrownItem.ThrowItem();
                    return;
                }


                if ((tapPos.X >= _ThrowDirectionArrowRight.X && tapPos.X <= _ThrowDirectionArrowRight.X + _ThrowDirectionArrowRight.Width) && (tapPos.Y >= _ThrowDirectionArrowRight.Y && tapPos.Y <= _ThrowDirectionArrowRight.Y + _ThrowDirectionArrowRight.Height))
                {
                    //right arrow clicked
                    World.WorldManager.ThrownItem.ThrowDirection = Util.Helpers.PublicEnums.ItemMoveDirection.Right;
                    World.WorldManager.ThrowDirectionChosen = true;
                    World.WorldManager.ThrownItem.ThrowItem();
                    return;
                }


                if (!World.WorldManager.ThrowDirectionChosen && this.ThrowDirectionArrowsDrawn)
                {
                    //if no arrow has been clicked
                    //then dispose of arrows
                    this.DisposeThrowArrows();
                    World.WorldManager.ExitThrowingMode();
                }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// dispose of throw arrows
        /// and hide
        /// </summary>
        public void DisposeThrowArrows()
        {
            try
            {
                _ThrowDirectionArrowUp = new Rectangle(-1, -1, -1, -1);
                _ThrowDirectionArrowDown = new Rectangle(-1, -1, -1, -1);
                _ThrowDirectionArrowRight = new Rectangle(-1, -1, -1, -1);
                _ThrowDirectionArrowLeft = new Rectangle(-1, -1, -1, -1);

                _DrawThrowDirectionArrows = false;
                ThrowDirectionArrowsDrawn = false;



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion

        /// <summary>
        /// check if player tapped on avatar
        /// </summary>
        /// <param name="tap"></param>
        /// <returns></returns>
        public bool IsTapOnMe(int[] tap)
        {
            try
            {
                if ((tap[0] >= this.CurrentPosition.X && tap[0] <= this.CurrentPosition.X + this.Width) && (tap[1] >= this.CurrentPosition.Y && tap[1] <= this.CurrentPosition.Y + this.Height))
                {
                    return true;
                }


                return false;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return false;
            }
        }

        /// <summary>
        /// damage avatar
        /// </summary>
        /// <param name="damage"></param>
        public void HurtAvatar(int damage)
        {
            try
            {
                

                


                this.Health -= damage;

                //play hurt animation
                IsBeingHurt = true;
                _SetTime = Util.Cache.GameTime.TotalGameTime.TotalMilliseconds;

                DrawAvatarHurt = true;

                //update HUD

                //save
                World.StorageManager.SaveWorldInfo();

                //if health is <0, then avatar dies
                if (this.Health <= 0)
                {
                    AvatarDies();
                }






            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// game over
        /// avatar dies
        /// </summary>
        public void AvatarDies()
        {
            try
            {
                //show death



                //show game over screen
                Util.Cache.CurrentScreen = Util.Cache.Screen.GameOver;

                //clear everything?



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #region MOVEMENT

        /// <summary>
        /// Add checkpoint to the collection
        /// </summary>
        /// <param name="pos"></param>
        public void AddCheckpoint(Vector2 pos,TimeSpan T,Vector2 D)
        {
            ////declare
            //Helpers.MovePatternCheckpoint checkpoint;

            //try
            //{
            //    #region create new instance of move points collection if null

            //    if (this.MovePoints == null)
            //    {
            //        this.MovePoints = new List<Helpers.MovePatternCheckpoint>();
            //        this._MoveCheckpointIndex = 0;
            //        _IndexValueHolder = 0;
            //        _CurrentMoveCheckpoint = new Vector2(-1, -1);
            //        _PreviousCheckpoint = new Vector2(0, 0);
            //        _XReached = false;
            //        _YReached = false;
            //        _AddCheckpoint = true;
            //        _CurrentMoveCheckpointIndex = 0;
            //        _MoveDirectionDetermined = false;
            //    }
            //    #endregion

            //    //new checkpoint
            //    checkpoint = new Helpers.MovePatternCheckpoint();
            //    checkpoint.Pos = pos;
            //    checkpoint.delta = D;
            //    checkpoint.timestamp = T;

            //    if (!_AddCheckpoint)
            //    {
            //        if (_MoveCheckpointIndex - _IndexValueHolder == 5)
            //        {
            //            _AddCheckpoint = true;
            //        }
            //    }

            //    //determine if current checkpoint is even, if yes, then it's visible (drawing every second checkpoint)
            //    //checkpoint+1 as we want to check next index not the current one
            //    if (_AddCheckpoint)
            //    {
            //        checkpoint.Visible = true;
            //        //this.MovePoints.Add(pos);//add to the collection
            //        _IndexValueHolder = _MoveCheckpointIndex;//save current index value
            //        _AddCheckpoint = false;


            //    }
            //    else
            //    {
            //        checkpoint.Visible = false;
            //    }

            //    //add
            //    this.MovePoints.Add(checkpoint);
            //    //if _current checkpoint is -1 and -1 (x,y) then assign (first checkpoint)
            //    if (_CurrentMoveCheckpoint.X == -1 && _CurrentMoveCheckpoint.Y == -1)
            //    {
            //        _CurrentMoveCheckpoint = pos;
            //    }

            //    //increment index counter 
            //    _MoveCheckpointIndex += 1;


            //    //add 1 to _moveCheckpointIndex (next index)


            //}
            //catch (Exception ex)
            //{
            //    Util.ErrorLogging.LogError(ex);
            //    return;
            //}
        }

        /// <summary>
        /// Draw move pattern
        /// </summary>
        public void DrawMovePattern()
        {
            try
            {
                //if move pattern canceled, then return
                if (this.DrawingMovePatternCanceled)
                {
                    return;
                }

                if (this.IsFollowing)
                {
                    if (Util.Cache.Avatar.MovePoints != null)
                    {
                        for (int i = 0; i < this.MovePoints.Count; i++)
                        {
                            if (this.MovePoints[i].Visible)
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("Dot").Text2D, new Rectangle((int)this.MovePoints[i].Pos.X + (this.MovePoints[i].Pos.Width / 2), (int)this.MovePoints[i].Pos.Y + (this.MovePoints[i].Pos.Height / 2), World.WorldManager.WorldConfig.CheckpointWidth, World.WorldManager.WorldConfig.CheckpointHeight), Color.White);
                                //Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, ".", new Vector2((int)this.MovePoints[i].X, (int)this.MovePoints[i].Y), 80, Color.Black);
                            }

                        }
                    }

                    //draw avatar destination
                    //DrawAvatarDestination();
                }

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// draw avatar's destination 
        /// represented by red X
        /// </summary>
        public void DrawAvatarDestination()
        {
            try
            {
                if (this.IsFollowing)
                {
                    Util.Cache.Draw(Util.Cache.GetTexture("XMark").Text2D, new Rectangle((int)this.MovePoints[this.MovePoints.Count - 1].Pos.X, (int)this.MovePoints[this.MovePoints.Count - 1].Pos.Y, World.WorldManager.WorldConfig.CheckpointWidth*3, World.WorldManager.WorldConfig.CheckpointHeight*3), Color.White);
                }
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// End following a drawn move pattern
        /// </summary>
        public void EndFollowing()
        {
            try
            {

                this.FuturePosition = this.CurrentPosition;

                this.SetIdle(this.Position);

                this.DrawingMovePatternEnd = false;
                this.DrawingMovePatternStarted = false;
                this.DrawingMovePatternCanceled = false;
                this.MovePoints.Clear();
                this.MovePoints = null;
                this._MoveCheckpointIndex = 0;
                _IndexValueHolder = 0;
                CurrentMoveCheckpoint = null;
                _XReached = false;
                _YReached = false;
                _AddCheckpoint = true;
                _CurrentMoveCheckpointIndex = 0;
                _MoveDirectionDetermined = false;
                IsFollowing = false;
                CheckpointsReached = 0;
                IsMoving = false;


                if (World.ScannerManager.AutoScannerON)
                {
                    //if auto scanner is on, then end showing nodes as avatar finishes the moving
                    World.ScannerManager.ExitChooseNodesMode();
                    World.ScannerManager.EndScanningProcess();
                }
                else
                {
                    //if scanning was pending, then start choosing nodes now
                    if (World.ScannerManager.ChoosingNodesModePending)
                    {
                        World.ScannerManager.ChooseNodesToBeScanned();
                    }
                }

                //start battery refill process
                World.ScannerManager.BatteryLevelRefillTime = Util.Cache.GameTime.TotalGameTime.TotalMilliseconds;

                ;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }



    



        /// <summary>
        /// follow the move pattern that user
        /// has drawn on the screen
        /// </summary>
        public void FollowMovePattern()
        {
            //declare
            Rectangle avatarRect;
            Rectangle checkpointRect=new Rectangle(-1,-1,-1,-1);
           


            try
            {
                if (this.MovePoints == null || !IsMoving)
                {
                    return;
                }

                if (this.MovePoints.Count == 1 && this.MovePoints[0].IsEndOfPath)
                {
                    EndFollowing();
                    return;

                }

              
              

                //determine direction
                if (!_MoveDirectionDetermined)
                {
                    CurrentMoveCheckpoint = this.MovePoints[0];

                    if (this.MovePoints.Count > 1)
                    {
                        TargetMoveCheckpoint = this.MovePoints[1];
                    }

                    _CurrentMoveCheckpointIndex = 0;

                    DetermineAndSetWalkDirection();
                    //ValidateCheckpointFollowDirections();
                    ////set current move checkpoint to the first checkpoint

                   
                }

                //RemoveDuplicatesFromMovePointsList();

                //is following -yeah
                IsFollowing = true;
                //reset future position
                this.FuturePosition = this.CurrentPosition;

                //SetAvatarPositionBasedOnCheckpointDirection();


                    #region update position

                    switch (CurrentState)
                    {
                        case (States.GoRight1):
                            {

                                #region GO RIGHT

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.X += this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go right
                                    this.CurrentPosition.X += this.AvatarWalkStep;

                                   
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }

                                break;

                                #endregion
                            }
                        case (States.DiveRight):
                            {

                                #region dive right
                                //increment future position to see if avatar is free to go
                                this.FuturePosition.X += this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go right
                                    this.CurrentPosition.X += this.AvatarWalkStep;

                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }
                                break;

                                #endregion
                            }
                        case (States.LayDownRight):
                            {
                                #region lay down right
                                //increment future position to see if avatar is free to go
                                this.FuturePosition.X += this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //crawl right
                                    this.CurrentPosition.X += this.AvatarWalkStep;

                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }




                                break;

                                #endregion
                            }
                        case (States.GoLeft1):
                            {
                                #region GO LEFT

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.X -= this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go left
                                    this.CurrentPosition.X -= this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }



                                break;

                                #endregion
                            }
                        case (States.DiveLeft):
                            {
                                #region dive left

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.X -= this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //dive left
                                    this.CurrentPosition.X -= this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }



                                break;

                                #endregion
                            }
                        case (States.LayDownLeft):
                            {
                                #region lay down left

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.X -= this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go left
                                    this.CurrentPosition.X -= this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }



                                break;

                                #endregion
                            }
                        case (States.GoUp1):
                            {
                                #region GO UP

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.Y -= this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go up
                                    this.CurrentPosition.Y -= this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }



                                break;

                                #endregion
                            }
                        case (States.DiveUp):
                            {
                                #region dive up

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.Y -= this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go up
                                    this.CurrentPosition.Y -= this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }



                                break;

                                #endregion
                            }
                        case (States.LayDownUp):
                            {
                                #region lay down up

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.Y -= this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go up
                                    this.CurrentPosition.Y -= this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }



                                break;

                                #endregion
                            }
                        case (States.GoDown1):
                            {

                                #region GO DOWN
                                //increment future position to see if avatar is free to go
                                this.FuturePosition.Y += this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go down 
                                    this.CurrentPosition.Y += this.AvatarWalkStep;
                                    
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }

                                break;

                                #endregion
                            }
                        case (States.DiveDown):
                            {

                                #region dive down

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.Y += this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go down
                                    this.CurrentPosition.Y += this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }

                                break;

                                #endregion
                            }
                        case (States.LayDown):
                            {

                                #region lay down

                                //increment future position to see if avatar is free to go
                                this.FuturePosition.Y += this.AvatarWalkStep;

                                if (Levels.LevelManager.CurrentMap.IsFreeToGo())
                                {
                                    //go down
                                    this.CurrentPosition.Y += this.AvatarWalkStep;
                                }
                                else
                                {
                                    EndFollowing();
                                    return;
                                }

                                break;

                                #endregion
                            }

                    }

                    #endregion

                    #region auto scanner

                    if (World.ScannerManager.AutoScannerON)
                    {
                        if (World.ScannerManager.BatteryLevel > 0)
                        {
                            World.ScannerManager.ChooseNodesToBeScanned();
                        }
                    }


                    #endregion


                    #region avatar got to the checkpoint?



                    //create avatar rect
                    avatarRect = new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, this.Width, this.Height);

                    //if center of the avatar is in the center
                    if (avatarRect.X == this.MovePoints[1].Pos.X && avatarRect.Y == this.MovePoints[1].Pos.Y)
                    {
                        _XReached = true;
                        _YReached = true;
                    }

               
                //set next checkpoint
                if (_XReached && _YReached)
                {
                    //increase checkpoints reached counter
                    CheckpointsReached += 1;

                    #region take away battery level if auto scanner is on

                    if (World.ScannerManager.AutoScannerON)
                    {
                        
                        //take away auto scanner battery (if _checkpoints reached=takeAwayBatteryStep
                        if (World.ScannerManager.TakeAwayAutoScannerBattery(CheckpointsReached))
                        {
                            //reset checkpoints reached if battery was taken away.
                            //we can take away another battery portion when necessary
                            CheckpointsReached = 0;
                        }
                    }

                    #endregion


                    #region in case if this was the last checkpoint and the goal position has been reached

                    if (this.MovePoints[1].IsEndOfPath)
                    {
                        //this was the last checkpoint
                        //reset all flags
                        this.EndFollowing();


                        return;
                    }

                    #endregion

                    //set current avatar's pos
                    //this.CurrentPosition.X = _CurrentMoveCheckpoint.Pos.X;
                    //this.CurrentPosition.Y = _CurrentMoveCheckpoint.Pos.Y;

                    

                    if (_CurrentMoveCheckpointIndex < this.MovePoints.Count)
                    {
                        //make the reached checkpoint invisible
                        this.MovePoints[_CurrentMoveCheckpointIndex].Visible = false;
                        //remove reached checkpoint from the list
                        this.MovePoints.RemoveAt(0);

                        //increment current index by 1 (index of item from move checkpoints)
                        //_CurrentMoveCheckpointIndex += 1;

                        //get next current checkpoint
                        CurrentMoveCheckpoint = this.MovePoints[0];
                        //set target (if exists
                        if (this.MovePoints.Count > 1)
                        {
                            TargetMoveCheckpoint = this.MovePoints[1];
                        }

                        //if target move checkpoint has "StartOfPath" property set to true
                        //then it must mean that a change in the path has been made
                        //it is impossible to have start of path checkpoint with index >0
                        //intially node 0 is start of path
                        if (TargetMoveCheckpoint.IsStartOfPath)
                        {
                            //remove current move checkpoint 
                            //and set target move checkpoint as current
                            //NEW PATH STARTS HERE (new, modified path)
                            this.MovePoints.RemoveAt(0);
                            CurrentMoveCheckpoint = this.MovePoints[0];
                            //set target (if exists
                            if (this.MovePoints.Count > 1)
                            {
                                TargetMoveCheckpoint = this.MovePoints[1];
                            }
                        }

                        if (World.ScannerManager.AutoScannerON)
                        {
                            //if auto scanner is on, then end showing nodes as avatar finishes the moving
                            World.ScannerManager.ExitChooseNodesMode();
                            World.ScannerManager.EndScanningProcess();
                        }
                       

                        //reset flags
                        _XReached = false;
                        _YReached = false;
                        _MoveDirectionDetermined = false;
                    }
                    else
                    {
                        //this was the last checkpoint
                        //reset all flags
                        this.EndFollowing();

                     

                        return;
                    }
                }
                

                #endregion


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Removes duplicates
        /// from a list of move points
        /// </summary>
        public void RemoveDuplicatesFromMovePointsList()
        {
            //declare
            int occurenceCt = 0; //used to count how many times a move point occurs on the list of move points

            try
            {
                if (this.MovePoints != null)
                {
                    for (int i = 0; i < this.MovePoints.Count; i++)
                    {
                        occurenceCt = 0;

                        for (int i1 = 0; i1 < this.MovePoints.Count; i1++)
                        {
                            if (this.MovePoints[i].Pos.X == this.MovePoints[i1].Pos.X && this.MovePoints[i].Pos.Y == this.MovePoints[i1].Pos.Y)
                            {
                                occurenceCt += 1;

                                //if this is a second instance of the same move point...
                                if (occurenceCt >= 2)
                                {
                                    //remove from the list
                                    //the instance that makes a second copy of the same move point
                                    this.MovePoints.RemoveAt(i1);
                                    break;

                                }
                            }
                        }
                    }
                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


      
        /// <summary>
        /// Avatar has to get to some checkpoint
        /// -set direction before walking 
        /// </summary>
        public void DetermineAndSetWalkDirection()
        {
            try
            {
                switch (this.Position)
                {
                    case Util.Helpers.PublicEnums.AvatarPosition.Stand:
                        {
                            switch (CurrentMoveCheckpoint.FollowDirection)
                            {
                                case Helpers.MovePatternCheckpoint.Direction.None:
                                    {
                                        //set idle
                                        //based on next move point (basically make avatar face next move point)
                                        SetAvatarStateBasedOnNextMovePoint();


                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Up:
                                    {
                                        SetState(States.GoUp1);

                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Down:
                                    {
                                        SetState(States.GoDown1);
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Left:
                                    {
                                        SetState(States.GoLeft1);
                                        break;

                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Right:
                                    {
                                        SetState(States.GoRight1);




                                        break;
                                    }
                            }



                            break;

                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Lay:
                        {

                            break;
                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Dive:
                        {


                            switch (CurrentMoveCheckpoint.FollowDirection)
                            {
                                case Helpers.MovePatternCheckpoint.Direction.None:
                                    {
                                        //set idle
                                        //based on next move point (basically make avatar face next move point)
                                        SetAvatarStateBasedOnNextMovePoint();
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Up:
                                    {
                                        SetState(States.DiveUp);

                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Down:
                                    {
                                        SetState(States.DiveDown);
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Left:
                                    {
                                        SetState(States.DiveLeft);
                                        break;

                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Right:
                                    {
                                        SetState(States.DiveRight);
                                        break;
                                    }
                            }

                            break;

                        }


                }

                _MoveDirectionDetermined = true;
               

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }



        /// <summary>
        /// validate if follow directions assigned
        /// to the checkpoints are correct
        /// </summary>
        public void ValidateCheckpointFollowDirections()
        {
            try
            {
                #region validate direction

                for (int i = 0; i < this.MovePoints.Count; i++)
                {

                    //check if set direction makes sense and modify it if not
                    //example: if current direction is left and previous dir was down, and next 2 directions are down, then change that left to down.
                    //1. if current follow direction is the same as previous follow direction
                    //2. if next follow direction is the same
                    //3. if the follow direction after that is the same
                    if (i - 1 >= 0)
                    {
                        if ((this.MovePoints[i].FollowDirection == this.MovePoints[i - 1].FollowDirection))
                        {
                            //if the next one is the same the leave it
                            if (i + 1 <= this.MovePoints.Count - 1)
                            {
                                if (this.MovePoints[i].FollowDirection != this.MovePoints[i + 1].FollowDirection)
                                {
                                    //if next one is not the same
                                    //then set the direction to the same as next one
                                    this.MovePoints[i].FollowDirection = this.MovePoints[i + 1].FollowDirection;
                                }
                            }

                        }
                        else
                        {
                            //previous checkpoint is different, check if next 2 are the same or different
                            if (i + 1 <= this.MovePoints.Count - 1)
                            {
                                if (this.MovePoints[i].FollowDirection != this.MovePoints[i + 1].FollowDirection)
                                {
                                    //if next one is the same check the next one
                                    if (i + 2 <= this.MovePoints.Count - 1)
                                    {
                                        if (this.MovePoints[i].FollowDirection != this.MovePoints[i + 2].FollowDirection)
                                        {
                                            //change the direction
                                            this.MovePoints[i].FollowDirection = this.MovePoints[i + 1].FollowDirection;
                                        }
                                    }


                                }
                                else
                                {
                                    //next one is the same
                                    //check if next one after that is the same as well
                                    if (i + 2 <= this.MovePoints.Count - 1)
                                    {
                                        if (this.MovePoints[i].FollowDirection != this.MovePoints[i + 2].FollowDirection)
                                        {
                                            //change the direction as there are only 2 checkpoints of that kind and they are surrounded by other direction checkpoints
                                            this.MovePoints[i].FollowDirection = this.MovePoints[i + 1].FollowDirection;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

       

        /// <summary>
        /// set avatar position based on checkpoint direction
        /// </summary>
        public void SetAvatarStateBasedOnNextMovePoint()
        {
            try
            {
                if ((this.MovePoints==null)||(this.MovePoints.Count==1)||(this.MovePoints[_CurrentMoveCheckpointIndex + 1] == null))
                {
                    return;
                }

                switch (this.Position)
                {
                    case Util.Helpers.PublicEnums.AvatarPosition.Stand:
                        {
                            switch (this.MovePoints[_CurrentMoveCheckpointIndex+1].FollowDirection)
                            {
                                case Helpers.MovePatternCheckpoint.Direction.None:
                                        {
                                            break;

                                        }
                                case Helpers.MovePatternCheckpoint.Direction.Right:
                                    {
                                        SetState(States.GoRight1);


                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Left:
                                    {
                                        SetState(States.GoLeft1);
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Down:
                                    {
                                        SetState(States.GoDown1);
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Up:
                                    {
                                        SetState(States.GoUp1);
                                        break;
                                    }

                            }

                            break;
                        }
                    case Util.Helpers.PublicEnums.AvatarPosition.Dive:
                        {
                            switch (this.MovePoints[_CurrentMoveCheckpointIndex].FollowDirection)
                            {
                                case Helpers.MovePatternCheckpoint.Direction.Right:
                                    {
                                        SetState(States.DiveRight);


                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Left:
                                    {
                                        SetState(States.DiveLeft);
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Down:
                                    {
                                        SetState(States.DiveDown);
                                        break;
                                    }
                                case Helpers.MovePatternCheckpoint.Direction.Up:
                                    {
                                        SetState(States.DiveUp);
                                        break;
                                    }
                            }

                            break;
                        }
            }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion


        #region DRAW

        /// <summary>
        /// Draw main character
        /// </summary>
        /// <param name="position"></param>
        public void DrawCharacter()
        {

            try
            {
                //use DrawHurtingAvatar if avatar is getting hurt
                if (IsBeingHurt)
                {
                    DrawHurtingCharacter();
                    return;
                }

                #region draw char

                switch (CurrentState)
                {
                    case States.IdleRight:
                        {
                            
                            Util.Cache.Draw(Util.Cache.GetTexture("charIdleRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.IdleLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charIdleLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.IdleUp:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charIdleUp").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.IdleDown:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charIdleFront").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoDown1:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkDown1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoDown2:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkDown2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoUp1:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkUp1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoUp2:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkUp2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoLeft1:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charGoLeft1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoLeft2:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charGoLeft2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoRight1:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoRight2:
                        {

                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;
                        }
                    case States.GoCrossDownRight1:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkCrossDownRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossDownRight2:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossLeftDown1:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkCrossDownLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossLeftDown2:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossUpRight1:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkCrossUpRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossUpRight2:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossLeftUp1:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charWalkCrossUpLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.GoCrossLeftUp2:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                            break;
                        }
                    case States.Hurt1:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;


                        }
                    case States.Hurt2:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;


                        }
                    case States.Death1:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.Death2:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charGoRight2").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDown:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDown").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDownRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDownLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownCrossDownRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDownRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownCrossDownLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDownRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownCrossUpRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDownRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownCrossUpLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("charLayDownRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.LayDownUp:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("CharLayDownUp").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveUp:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveUp").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveDown:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveDown").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveCrossUpLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveCrossUpRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveCrossDownLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveLeft").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.DiveCrossDownRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.ThrowDown:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.ThrowUp:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.ThrowRight:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                    case States.ThrowLeft:
                        {
                            Util.Cache.Draw(Util.Cache.GetTexture("diveRight").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                            break;

                        }
                }
                #endregion


                //draw an umbrella if avatar is spotted by npc
                //but hidden behind some obstacle
                _DrawUmbrella();


                #region draw throw direction arrows
                if (this._DrawThrowDirectionArrows && !World.WorldManager.ThrowDirectionChosen)
                {
                    Util.Cache.Draw(Util.Cache.GetTexture("ArrowUp").Text2D, _ThrowDirectionArrowUp, Color.White);
                    Util.Cache.Draw(Util.Cache.GetTexture("ArrowDown").Text2D, _ThrowDirectionArrowDown, Color.White);
                    Util.Cache.Draw(Util.Cache.GetTexture("ArrowLeft").Text2D, _ThrowDirectionArrowLeft, Color.White);
                    Util.Cache.Draw(Util.Cache.GetTexture("ArrowRight").Text2D, _ThrowDirectionArrowRight, Color.White);

                    //set drawn flag to true
                    this.ThrowDirectionArrowsDrawn = true;

                }

                #endregion

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// Draw main character
        /// </summary>
        /// <param name="position"></param>
        public void DrawHurtingCharacter()
        {

            try
            {
                if (DrawAvatarHurt)
                {

                    #region draw char hurting

                    switch (CurrentState)
                    {
                        case States.IdleRight:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);


                                break;
                            }
                        case States.IdleLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.IdleUp:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.IdleDown:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoDown1:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoDown2:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoUp1:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoUp2:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoLeft1:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoLeft2:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoRight1:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("charGoRight1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoRight2:
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;
                            }
                        case States.GoCrossDownRight1:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossDownRight2:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossLeftDown1:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossLeftDown2:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossUpRight1:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossUpRight2:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossLeftUp1:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.GoCrossLeftUp2:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);
                                break;
                            }
                        case States.Death1:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.Death2:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDown:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownCrossDownRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownCrossDownLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownCrossUpRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownCrossUpLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.LayDownUp:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveUp:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveDown:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveCrossUpLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveCrossUpRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveCrossDownLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.DiveCrossDownRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("diveHurt").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.ThrowDown:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.ThrowUp:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.ThrowRight:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                        case States.ThrowLeft:
                            {
                                Util.Cache.Draw(Util.Cache.GetTexture("avatarHurt1").Text2D, new Rectangle((int)this.CurrentPosition.X, (int)this.CurrentPosition.Y, Width, Height), Color.White);

                                break;

                            }
                    
                    }
                    #endregion


                    //if current time-set time
                    if (Util.Cache.GameTime.TotalGameTime.TotalMilliseconds - this._SetTime > 500)
                    {
                        Util.Cache.DrawString(Util.Cache.GetFont("default").FontFace, "HURT", new Vector2(200, 200), 20, Color.Red);
                        IsBeingHurt = false;
                        DrawAvatarHurt = false;
                    }

                }
               

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        #endregion


        #endregion




    }
}
